package org.Test;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.Component.CommentBar;
import org.Component.PostMenuBar;
import org.Component.SearchPanel;
import org.JsonMsg.Post;
import org.Panel.*;
import org.Tools.StringOP;
import org.implement.Panel.PanelSize;
import org.implement.Panel.PanelSkip;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.lang.reflect.Type;
import java.util.List;

public class GUITest {
    public static void main(String[] args) {

        // 创建一个简单的线边框，颜色为黑色，粗细为1像素
        Border border = BorderFactory.createLineBorder(Color.BLACK, 1);

        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("GUITest");
        frame.setSize(1200, 800);
        frame.setLocationRelativeTo(null);
        frame.setLayout(null);

        //母控件大小接口
        PanelSize panelSize = new PanelSize() {
            @Override
            public int getWidth() {
                return 1200;
            }

            @Override
            public int getHeight() {
                return 800;
            }
        };
        //母控件跳转接口
        PanelSkip panelSkip = new PanelSkip() {
            @Override
            public void skip(int panelid) {

            }
        };

        //评论界面
        CommentPanel cp = new CommentPanel(panelSkip);
        CommentBar com = new CommentBar("svc","fsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffdsfsajdlfhlkasdhfakljsdhfklajhsdsadfasdfasdfsdffds","2012-12-23 16:23",cp);
        cp.addCommentBar(com);
        //滚动界面
        ScrollPanel scrollPanel = new ScrollPanel(frame.getWidth(), frame.getHeight());
        scrollPanel.setPanel(cp);


        PersonalPanel personalPanel = new PersonalPanel(panelSkip,panelSize);
        personalPanel.myReplySum = "20";
        personalPanel.Run();
//        frame.add(personalPanel);
        PostMenuBar postMenuBar = new PostMenuBar(panelSize,panelSkip);

        PostPanel postPanel = new PostPanel(panelSize,panelSkip);


        //帖子操作界面
        StringOP op1 = new StringOP();
        String msg = "[Post(postId=6, userId=2, title=测试2, content=呵呵呵呵, createdAt=2024-12-20 17:23:53.0, updatedAt=2024-12-20 21:40:04.0, likesCount=1, repliesCount=0)]";
        msg = op1.JsonStr(msg);
        System.out.println(msg);

        Gson gson = new Gson();
        // 由于要解析为List<Post>类型，需要使用TypeToken来获取准确的类型信息
        Type listType = new TypeToken<java.util.List<Post>>() {}.getType();
        List<Post> postList = gson.fromJson(msg, listType);
        PostOP postOP = new PostOP(panelSize,panelSkip,postList.get(0));

        //启用的界面
        frame.add(personalPanel);

//        MouseStyleTest(border, frame);
//        frame.add(new PlayPanel());

        frame.setVisible(true);

        //模拟动态运行
        while(true){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
//            scrollPanel.run();
//            postPanel.Run();
        }

    }

    //鼠标样式更改测试
    private static void MouseStyleTest(Border border, JFrame frame) {
        JLabel label = new JLabel("鼠标移动到这里");
        label.setBounds(0,0,100,50);
        label.setBorder(border);

        frame.add(label);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                //鼠标移动至JLabel中时,改变鼠标指针样式为可点击状态
                label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            }
        });
    }
}
